<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
   <title>项目管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" lay-filter="example" >
    <div class="layui-tab">
        <ul class="layui-tab-title">
          <li class="layui-this">基础资料</li>
          <li>内容设置</li>
        </ul>
        <div class="layui-tab-content">
          <div class="layui-tab-item layui-show">
            <div class="layui-form-item">
                <label class="layui-form-label required">主标题</label>
                <div class="layui-input-block">
                    <input type="hidden" name="id" id="id" value="">
                    <input type="text" name="name" id="name" lay-verify="title" lay-reqtext="主标题" placeholder="主标题" value="" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">分类</label>
                <div class="layui-input-block">
                    <select name="class_id" id="class_id">
                        <option >选择分类</option>
                    </select>
                </div>
            </div>
            
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">图片</label>
                    <input type="hidden" name="course_image" id="course_image" value="">
                    <div class="layui-input-block">
                        <div class="layui-upload">
                            <button type="button" class="layui-btn layui-btn-primary" id="cateBtn">
                                <i class="icon icon-upload3"></i>点击上传</button>
                            <div class="layui-upload-list">
                                <img class="layui-upload-img" style="width: 200px;height: 100px;" id="cateImage" src="">
                                <p id="demoText"></p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">图片1</label>
                    <input type="hidden" name="course_image1" id="course_image1" value="">
                    <div class="layui-input-block">
                        <div class="layui-upload">
                            <button type="button" class="layui-btn layui-btn-primary" id="cateBtn1">
                                <i class="icon icon-upload3"></i>点击上传</button>
                            <div class="layui-upload-list">
                                <img class="layui-upload-img" style="width: 200px;height: 100px;" id="cateImage1" src="">
                                <p id="demoText"></p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">图片2</label>
                    <input type="hidden" name="course_image2" id="course_image2" value="">
                    <div class="layui-input-block">
                        <div class="layui-upload">
                            <button type="button" class="layui-btn layui-btn-primary" id="cateBtn2">
                                <i class="icon icon-upload3"></i>点击上传</button>
                            <div class="layui-upload-list">
                                <img class="layui-upload-img" style="width: 200px;height: 100px;" id="cateImage2" src="">
                                <p id="demoText"></p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">图片3</label>
                    <input type="hidden" name="course_image3" id="course_image3" value="">
                    <div class="layui-input-block">
                        <div class="layui-upload">
                            <button type="button" class="layui-btn layui-btn-primary" id="cateBtn3">
                                <i class="icon icon-upload3"></i>点击上传</button>
                            <div class="layui-upload-list">
                                <img class="layui-upload-img" style="width: 200px;height: 100px;" id="cateImage3" src="">
                                <p id="demoText"></p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">图片4</label>
                    <input type="hidden" name="course_image4" id="course_image4" value="">
                    <div class="layui-input-block">
                        <div class="layui-upload">
                            <button type="button" class="layui-btn layui-btn-primary" id="cateBtn4">
                                <i class="icon icon-upload3"></i>点击上传</button>
                            <div class="layui-upload-list">
                                <img class="layui-upload-img" style="width: 200px;height: 100px;" id="cateImage4" src="">
                                <p id="demoText"></p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">图片5</label>
                    <input type="hidden" name="course_image5" id="course_image5" value="">
                    <div class="layui-input-block">
                        <div class="layui-upload">
                            <button type="button" class="layui-btn layui-btn-primary" id="cateBtn5">
                                <i class="icon icon-upload3"></i>点击上传</button>
                            <div class="layui-upload-list">
                                <img class="layui-upload-img" style="width: 200px;height: 100px;" id="cateImage5" src="">
                                <p id="demoText"></p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

          </div>
          <div class="layui-tab-item">
        
                <div class="layui-form-item">
                    <label class="layui-form-label ">简要</label>
                    <div class="layui-input-block">
                        <textarea class="layui-textarea " name="course_introduce" id="course_introduce"  ></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="types" value="1" title="上架"  checked="">
                        <input type="radio" name="types" value="2" title="待审核"> 
                        <input type="radio" name="types" value="3" title="审核拒绝" >
                        <input type="radio" name="types" value="4" title="下架"> 
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">关键词</label>
                    <div class="layui-input-block">
                        <input type="text" name="gjc_id" id="gjc_id"  value="" ts-selected=""  class="layui-input">
                    </div>
                    <div class="layui-input-block layui-word-aux" style="margin-top: 10px;"  id="viewgjc"></div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label required">关联人物</label>
                    <div class="layui-input-block">
                        <input type="text" name="teacher_id" id="teacher_id"  value="" ts-selected=""  class="layui-input">
                    </div>
                    <div class="layui-input-block layui-word-aux" style="margin-top: 10px;" id="viewteacher"></div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">阅读量</label>
                        <div class="layui-input-block">
                            <input type="number" name="course_play" id="course_play" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">价格</label>
                        <div class="layui-input-block">
                            <input type="number" name="price" id="price" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                        
                    <div class="layui-inline">
                        <label class="layui-form-label">积分</label>
                        <div class="layui-input-block">
                            <input type="number" name="score" id="score" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">排序</label>
                        <div class="layui-input-block">
                            <input type="number" name="sort" id="sort" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">评价数量</label>
                        <div class="layui-input-block">
                            <input type="number" name="pj_qu" id="pj_qu" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">分享数量</label>
                        <div class="layui-input-block">
                            <input type="number" name="fx_qu" id="fx_qu" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">点赞数量</label>
                        <div class="layui-input-block">
                            <input type="number" name="da_qu" id="da_qu"  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">href</label>
                    <div class="layui-input-block">
                        <input type="text" name="href" id="href"  autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                    </div>
                </div>
          </div>
        </div>
    </div>
    <script id="demo" type="text/html">
        {{#  layui.each(d.list, function(index, item){ }}
        <button type="button" class="layui-btn layui-btn-primary layui-btn-sm layui-btn-radius">{{item.name}}</button>
        {{#  }); }}
    </script>
  
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js" charset="utf-8"></script>
<script>
    layui.use(['form','upload','http','laytpl'], function () {
        var form = layui.form,
            layer = layui.layer,
            uploadInst = layui.upload,
            wangEditor = layui.wangEditor,
            $ = layui.$,
            laytpl = layui.laytpl,
            http  = layui.http,
            apiurl =http.api;


        getClassify();
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            http.httpajax("Business/upAdEssay", data.field,"POST",function(res) {
                if(res.code === '0000'){
                    layer.msg(res.msg,{time:1000,icon:1},function(){
                        // 关闭弹出层
                        layer.close();
                        window.parent.location.reload();//刷新父页面
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    });
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            });
        });
        
        http.tableSele('#gjc_id', '选择关键词','Business/getKeyword',[[
                { type: 'checkbox' },
                { field: 'id', title: 'ID', width: 100 },
                { field: 'name', title: '标题'},
                ]]
            );

        http.tableSele('#teacher_id', '选择人物','Business/getTeacher',[[
            { type: 'checkbox' },
            { field: 'id', title: 'ID', width: 100 },
            { field: 'name', title: '名称'},
            { field: 's_name', title: '昵称'}
            ]]
        );
        
        function getClassify(){
            http.httpajax("Business/getClass",{'z_id':1},"POST",function(res) {
                if(res.code === '0000'){
                    for(var i =0;i<res.data.length;i++){
                        $("#class_id").append("<option value=\""+res.data[i].id+"\">"+res.data[i].name+"</option>");
                    }
                    //重新渲染
                    layui.form.render("select");
                    var id  = http.getQueryString('id');
                    if(id){
                        getInfo(id);
                    }
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                } 
            });
        }

        function getInfo(id){
            http.httpajax("Business/getEssayList",{'id':id},"POST",function(res) {
                if(res.code === '0000'){
                    $("#gjc_id").attr("ts-selected", res.data.gjc_id);
                    $("#teacher_id").attr("ts-selected", res.data.teacher_id);
                    tpl(res.data.keyword,"#viewgjc");
                    tpl(res.data.teacher,"#viewteacher");
                    $('#cateImage').attr('src',res.data.course_image);
                    $('#cateImage1').attr('src',res.data.course_image1);
                    $('#cateImage2').attr('src',res.data.course_image2);
                    $('#cateImage3').attr('src',res.data.course_image3);
                    $('#cateImage4').attr('src',res.data.course_image4);
                    $('#cateImage5').attr('src',res.data.course_image5);
                    form.val('example', res.data);
                    tpl(res.data.gjc_id,"","");
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                } 
            });
        }

        
        function tpl(data,viewid){
            var data ={"list": data};
            console.error("data",data);
            var getTemplate = $("#demo").html();
            laytpl(getTemplate).render(data, function (html) {
                $(viewid).html(html);
            });
        }
        
        http.uplode("cateBtn",function(res) {
            fattr("course_image","cateImage",res);
        });
        http.uplode("cateBtn1",function(res) {
            fattr("course_image1","cateImage1",res);
        });
        http.uplode("cateBtn2",function(res) {
            fattr("course_image2","cateImage2",res);
        });
        http.uplode("cateBtn3",function(res) {
            fattr("course_image3","cateImage3",res);
        });
        http.uplode("cateBtn4",function(res) {
            fattr("course_image4","cateImage4",res);
        });
        http.uplode("cateBtn5",function(res) {
            fattr("course_image5","cateImage5",res);
        });

        function fattr(name,img,res){
            if(res.code==200){
                $('#'+name).val(res.data);
                $('#'+img).attr('src',res.data);
                layer.msg("上传成功",{offset:['200px','450px'],icon:6});
            }else{
                //如果上传失败
                return layer.msg('上传失败');
            }
           
        }
    });
    
</script>
</body>
</html>